/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.client.utils.panels;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import lt.ntec.danblog.shared.utils.Utility;
import lt.ntec.danblog.shared.utils.text.EncodeBase64;

/**
 *
 * @author Tadas
 */
public class UtilityPanel extends VerticalPanel {

    private Utility utility;
    private TextArea input;
    private TextArea output;
    private Label label;
    
    public UtilityPanel() {
        label = new Label("Encode Base64");
        label.setStylePrimaryName("utility-processor-label");
        add(label);
        
        input = new TextArea();
        input.setWidth("100%");
        input.setHeight("150px");
        input.setStylePrimaryName("util-input-textarea");
        add(input);
        
        output = new TextArea();
        
        Button button = new Button("Process");
        button.addClickHandler(new ProcessClickHandler());
        button.setStylePrimaryName("utility-process-button");
        add(button);
        
        output.setWidth("100%");
        output.setHeight("150px");
        output.setStylePrimaryName("util-output-textarea");
        add(output);
        
        
        setStylePrimaryName("utility-controls-panel");
        setWidth("100%");
        
        utility = new EncodeBase64();
        
    }

    public Utility getUtility() {
        return utility;
    }

    public void setUtility(Utility utility) {
        this.utility = utility;
    }

    public Label getLabel() {
        return label;
    }
    
    private class ProcessClickHandler implements ClickHandler {

        @Override
        public void onClick(ClickEvent event) {
            if (getUtility() != null) {
                String toProcess = input.getText();
                output.setText(getUtility().getProcessedValue(toProcess));
            }
        }
        
    }
    
    
}
